package com.tim.app.ui.adapter.someone_homepage;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.util.TimeUtil;
import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Answer;
import com.tim.app.server.entry.Article;

import java.util.List;


/**
 * 文章
 */
public class HomepageArticleAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, Article> {

    private Context mContext;


    public HomepageArticleAdapter(Context mContext, List<Article> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_homepage_article,parent,false));
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder mHolder, int position, Article data) {
        if (data == null) {
            return;
        }
        ViewHolder holder = (ViewHolder) mHolder;

        if ( !TextUtils.isEmpty(data.getTitle())) {
            holder.tvArticleTitle.setText(data.getTitle());
        }
        if(!TextUtils.isEmpty(data.getContent())){
            holder.tvArticleContent.setText(data.getContent());
        }
        holder.tvPriseNumber.setText(mContext.getString(R.string.tvPriseNumber,String.valueOf(data.getAgreeCount())));
        holder.tvCommentNumber.setText(mContext.getString(R.string.tvCommentNumber,String.valueOf(data.getCommentCount())));
        holder.tvPublishTime.setText(TimeUtil.formatTimeRuleOne(mContext,data.getCreateTime()));
    }

    public class ViewHolder extends BaseRecyclerViewHolder {

        TextView tvArticleTitle, tvArticleContent, tvPriseNumber, tvCommentNumber, tvPublishTime;

        public ViewHolder(View itemView) {
            super(itemView);
            tvArticleTitle = (TextView) itemView.findViewById(R.id.tvArticleTitle);
            tvArticleContent = (TextView) itemView.findViewById(R.id.tvArticleContent);
            tvPriseNumber = (TextView) itemView.findViewById(R.id.tvPriseNumber);
            tvCommentNumber = (TextView) itemView.findViewById(R.id.tvCommentNumber);
            tvPublishTime = (TextView) itemView.findViewById(R.id.tvPublishTime);
        }

    }

}
